<template>
  <div class="all">
    <table width="100%" cellspacing="0">
      <thead>
        <tr>
          <th width="180px">表名</th>
          <th>大小</th>
          <th>碎片</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="(val,name) in list">
          <td>{{val.tableName}}</td>
          <td>{{val.size}}</td>
          <td>{{val.free}}</td>
          <td><i @click="submit(val)">[优化]</i></td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
  export default{
     inject:["reload"],
    data(){
      return{
        list:[
          {
            tableName:'ss_admin',
            size:'2.70',
            free:'50000'
          }
        ]
      }
      },
      methods:{
        Postdata(url,e){
          var _this=this
          this.$axios({
            method: "POST",
            url: '/api/'+url,
            headers: {'Content-Type': 'application/json'},
            data: {   adminName:_this.$cookies.get('adminName'),
                      token:_this.$cookies.get('token'),
                      tableName:e
                  },
          }).then(res=>{
            if(res.data.data!=null){
              res.data.data.forEach((val,keys)=>{
                var size =val.size/1024
                if(size>1024){
                    val.size=size/1024+'Mb'
                }else{
                  val.size=size+'Kb'
                }
                // console.log(val.size)
              })
               _this.list=res.data.data
            }else{
              _this.reload()
            }

            console.log(res)
          })
        },
        submit(e){
          this.Postdata('admin/database/optimize',e.tableName)
        }
      },

      mounted() {
        this.Postdata('admin/database/view','')
      }
      }
</script>

<style scoped>

  th{
    height: 30px;
    background: #eef3f7;
    border-bottom: 1px solid #d5dfe8;
    font-weight: normal;
  }
  tr{
    text-align: center;
  }
  td{
     border-bottom: 1px solid #d5dfe8;
     padding: 8px 0 0 8px;
  }
</style>
